Size

计算输入张量或向量的元素总个数(即形状各维度的乘积),并将结果写入输出地址。

输入:
  • output - 输出数据的地址,用于存储计算结果。

  • shape - 输入张量的形状(维度)数组地址。

  • n - 输入张量的维度数(Rank)。

  • core_mask - 核掩码(仅适用于共享存储版本)。

输出:
  • output - 存储元素总个数的地址。

支持平台:

FT78NE MT7004

备注

  • 由于该算子对于不同数据类型的具体实现一致,因此统一使用 size_ssize_p 命名,不再区分数据类型前缀(如 fp_, i8_ 等)。

  • 支持的数据类型包括:int8, int16, int32, fp32, fp64, cplx64, cplx128。

共享存储版本:

void size_s(int *output, int *shape, int n, int core_mask)

C调用示例:

 1#include <stdio.h>
 2#include <size.h>
 3
 4int main(int argc, char* argv[]) {
 5    int n = 4;
 6    // 假设 shape 为 {2, 3, 4, 5},元素总数为 120
 7    int *output = (int *)0xA0000000;
 8    int *shape = (int *)0xA0000100;
 9
10    // 实际使用中需确保 shape 地址处已存入维度数据
11    int core_mask = 0xff;
12
13    size_s(output, shape, n, core_mask);
14
15    return 0;
16}

私有存储版本:

void size_p(int *output, int *shape, int n)

C调用示例:

 1#include <stdio.h>
 2#include <size.h>
 3
 4int main(int argc, char* argv[]) {
 5    int n = 3;
 6    // 假设 shape 为 {10, 10, 4},元素总数为 400
 7    int *output = (int *)0x10000000;
 8    int *shape = (int *)0x10000040;
 9
10    // 实际使用中需确保 shape 地址处已存入维度数据
11    size_p(output, shape, n);
12
13    return 0;
14}